<template>
    <div class="box">
        <el-form
            :label-position="right"
            label-width="auto"
            :model="formLabelAlign"
            style="max-width: 600px"
        >
            <el-form-item label="Name">
                <el-input v-model="formData.username" />
            </el-form-item>
            <el-form-item label="Password">
                <el-input v-model="formData.password" type="password" />
            </el-form-item>
            <el-form-item label=" ">
                <el-button type="primary" @click="onSubmit">LOGIN</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import { post } from '@/util/request.js'
import router from '@/router'

const formData = reactive({
    username: '',
    password: ''
})

const onSubmit = () => {
    post('/admin/login', formData).then((resp) => {
        localStorage.setItem('_token', resp._token)
        router.push({ name: 'show-category' })
    })
}
</script>

<style scoped>
.box {
    width: 82%;
    margin: 30vh auto;
}
</style>
